package com.alameda.api.user;

import com.alameda.commonpent.mp.BaseService;
import com.alameda.user.dto.UserOrganizationDTO;
import com.alameda.user.pojo.UserOrganizationDO;
import com.alameda.user.vo.UserOrganizationVO;
import com.alameda.utils.PubUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * 用户组织 业务逻辑层
 *
 * @author Lv
 * @date 2024/04/27
 */
public interface UserOrganizationService extends BaseService<UserOrganizationDO> {
    /**
     * 查询组织列表
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     * @return
     */
    IPage<UserOrganizationVO> listOrganization(UserOrganizationDTO userOrganizationDTO);

    /**
     * 导出excel
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     */
    void export(UserOrganizationDTO userOrganizationDTO);

    /**
     * 获取一级组织信息
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     * @return
     */
    default List<UserOrganizationDO> findUserOrganization(UserOrganizationDTO userOrganizationDTO) {
        return this.lambdaQuery()
                .notIn(PubUtils.isNotNull(userOrganizationDTO.getId()), UserOrganizationDO::getId, userOrganizationDTO.getId())
                .isNull(UserOrganizationDO::getParentId)
                .list();
    }

    /**
     * 删除组织信息
     *
     * @param idList 组织id集合
     * @return
     */
    Boolean deleteByIds(List<Long> idList);

    /**
     * 加载所有子组织下拉框
     *
     * @return
     */
    default List<UserOrganizationDO> loadAllSonOrganization() {
        return this.lambdaQuery()
                .isNotNull(UserOrganizationDO::getParentId)
                .list();
    }

    /**
     * 新增或修改组织
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     * @return
     */
    Boolean saveOrUpdateOrganization(UserOrganizationDTO userOrganizationDTO);
}
